//
//  TabHederView.m
//  tabViewHeader
//
//  Created by mac on 2017/3/1.
//  Copyright © 2017年 zhiyu.com. All rights reserved.
//

#import "TabHederView.h"

#import "TodoHttpManager.h"
@implementation TabHederView


-(instancetype)initWithFrame:(CGRect)frame 
{
    
    self = [super initWithFrame:frame];
    if (self) {//这里可以写头部里面的布局
        _manager = [TodoHttpManager sharedManager];
        NSUserDefaults *userDefa = [NSUserDefaults standardUserDefaults];
        
        NSString *uid= [userDefa objectForKey:@"USER_ID"];
        //工作任务通知
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTDGuWenWork:) name:TDGuWenWork object:nil];
        [_manager userGuWenWorkID:uid];
        
        _oneView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 110)];
        _oneView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_oneView];
        //分割线
        UILabel *lineLab = [[UILabel alloc] initWithFrame: CGRectMake(0, 40, self.frame.size.width, 0.3f)];
        lineLab.backgroundColor = [UIColor grayColor];
        [_oneView addSubview:lineLab];
        UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 12, 100, 16)];
        titleLab.text = @"本月任务进度";
        titleLab.font = [UIFont systemFontOfSize:14];
        titleLab.textColor = [UIColor blackColor];
        [_oneView addSubview:titleLab];
        
    
        
        UILabel *paiLab = [[UILabel alloc] init];
        paiLab.text = @"当前排名 :";
        paiLab.textColor = [UIColor grayColor];
        paiLab.font = [UIFont systemFontOfSize:14];
        paiLab.textAlignment = NSTextAlignmentRight;
        [_oneView addSubview:paiLab];
        [paiLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(120, 14));
            make.top.equalTo(_oneView.mas_top).offset(13);
           // make.left.equalTo(titleLab.mas_right).offset(120);
            make.right.equalTo(self.mas_right).offset(-90);
            
        }];
        
        _paiMLab = [[UILabel alloc] init];
        _paiMLab.textColor = [UIColor colorWithHexString:@"#0FD4C9"];
        _paiMLab.text = @"22/24";
        _paiMLab.font = [UIFont systemFontOfSize:14];
        [_oneView addSubview:_paiMLab];
        [_paiMLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(60, 18));
            make.left.equalTo(paiLab.mas_right).offset(8);
            make.top.equalTo(_oneView.mas_top).offset(11);
        }];

        
        //时间lab
        _timeLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 50, 80, 16)];
        _timeLab.text = @"2017年7月  |";
        _timeLab.textColor = [UIColor grayColor];
        _timeLab.font = [UIFont systemFontOfSize:12];
        [_oneView addSubview:_timeLab];
        
        _finishLab = [[UILabel alloc] init];
        _finishLab.text = @"190.56";
        _finishLab.textColor = [UIColor colorWithHexString:@"#0FD4C9"];
        _finishLab.textAlignment = NSTextAlignmentLeft;
        _finishLab.font = [UIFont systemFontOfSize:12];
        [_oneView addSubview:_finishLab];
        [_finishLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(50, 12));
            make.top.equalTo(_oneView.mas_top).offset(52);
            make.left.equalTo(_timeLab.mas_right).offset(2);
     
        }];
  
        
        _allLab = [[UILabel alloc] init];
        _allLab.text = @"/400万元";
        _allLab.textColor = [UIColor grayColor];
        _allLab.font = [UIFont systemFontOfSize:12];
        [_oneView addSubview:_allLab];
        [_allLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(60, 12));
            make.top.equalTo(_oneView.mas_top).offset(52);
            make.left.equalTo(_finishLab.mas_right).offset(3);
            
        }];

        _biLiLab = [[UILabel alloc] init];
        _biLiLab.text = @"完成比例: 200%";
        _biLiLab.textColor = [UIColor grayColor];
        _biLiLab.font = [UIFont systemFontOfSize:14];
        [_oneView addSubview:_biLiLab];
        [_biLiLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(120, 12));
            make.top.equalTo(_oneView.mas_top).offset(52);
            make.right.equalTo(self.mas_right).offset(-5);
            
        }];

        
        
        
        
        
        _proView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
        [_proView setProgress:0.7 animated:NO];
        //设置轨道颜色
        _proView.trackTintColor = [UIColor colorWithHexString:@"#E3E3E3"];
        //设置进度颜色
        _proView.progressTintColor = [UIColor colorWithHexString:@"#0FD4C9"];
        _proView.layer.cornerRadius = 8.0f;
        _proView.layer.masksToBounds = YES;
        [_oneView addSubview:_proView];
        [_proView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(self.frame.size.width-15*2, 10.0f));
            make.left.equalTo(self.mas_left).offset(15);
            make.top.equalTo(_oneView.mas_top).offset(80);
        }];
        
        _twoView = [[UIView alloc] init];
        _twoView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_twoView];
        [_twoView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(self.frame.size.width, 100));
            make.top.equalTo(_oneView.mas_bottom).offset(10);
            
        }];
        
        UILabel *twoLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 12, 100, 16)];
        twoLab.text = @"本月客户数据";
        twoLab.font = [UIFont systemFontOfSize:14];
        twoLab.textColor = [UIColor blackColor];
        [_twoView addSubview:twoLab];
        //分割线
        UILabel *lineLab1 = [[UILabel alloc] initWithFrame: CGRectMake(0, 40, self.frame.size.width, 0.3f)];
        lineLab1.backgroundColor = [UIColor grayColor];
        [_twoView addSubview:lineLab1];
        

        NSInteger width = (self.frame.size.width)/11;
        
        _laiDLab = [[UILabel alloc] init];
        _laiDLab.textColor = OverColor;
        _laiDLab.font = [UIFont systemFontOfSize:12];
        //_laiDLab.backgroundColor = [UIColor redColor];
        //_laiDLab.text = @"220";
        _laiDLab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_laiDLab];
        [_laiDLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(width, 15));
            make.top.equalTo(lineLab.mas_top).offset(130);
            make.left.equalTo(self.mas_left).offset(width);
        }];
        
        _laiFLab = [[UILabel alloc] init];
        _laiFLab.textColor = OverColor;
        _laiFLab.font = [UIFont systemFontOfSize:12];
        //_laiFLab.backgroundColor = [UIColor orangeColor];
       // _laiFLab.text = @"270";
        _laiFLab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_laiFLab];
        [_laiFLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(width, 15));
            make.top.equalTo(lineLab.mas_top).offset(130);
            make.left.equalTo(_laiDLab.mas_right).offset(width);
        }];

        
        
        _chouLab = [[UILabel alloc] init];
        _chouLab.textColor = OverColor;
        _chouLab.font = [UIFont systemFontOfSize:12];
        //_chouLab.backgroundColor = [UIColor orangeColor];
        //_chouLab.text = @"270";
        _chouLab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_chouLab];
        [_chouLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(width, 15));
            make.top.equalTo(lineLab.mas_top).offset(130);
            make.left.equalTo(_laiFLab.mas_right).offset(width);
        }];
        
        _gouLab = [[UILabel alloc] init];
        _gouLab.textColor = OverColor;
        _gouLab.font = [UIFont systemFontOfSize:12];
        //_gouLab.backgroundColor = [UIColor orangeColor];
       // _gouLab.text = @"270";
        _gouLab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_gouLab];
        [_gouLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(width, 15));
            make.top.equalTo(lineLab.mas_top).offset(130);
            make.left.equalTo(_chouLab.mas_right).offset(width);
        }];
        

        _qianLab = [[UILabel alloc] init];
        _qianLab.textColor = OverColor;
        _qianLab.font = [UIFont systemFontOfSize:12];
        _qianLab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_qianLab];
        [_qianLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(width, 15));
            make.top.equalTo(lineLab.mas_top).offset(130);
            make.right.equalTo(self.mas_right).offset(-width);
        }];
        
        
        UILabel *lab1 = [[UILabel alloc] init];
       // lab1.textColor = OverColor;
        lab1.font = [UIFont systemFontOfSize:12];
        //lab1.backgroundColor = [UIColor blueColor];
        lab1.text = @"来电";
        lab1.textAlignment = NSTextAlignmentCenter;
        [self addSubview:lab1];
        [lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(width, 15));
            make.top.equalTo(lineLab.mas_top).offset(150);
            make.left.equalTo(self.mas_left).offset(width);
        }];
        
        
        
        UILabel *lab2 = [[UILabel alloc] init];
       // lab2.textColor = OverColor;
        lab2.font = [UIFont systemFontOfSize:12];
        //lab2.backgroundColor = [UIColor blueColor];
        lab2.text = @"来访";
        lab2.textAlignment = NSTextAlignmentCenter;
        [self addSubview:lab2];
        [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(width, 15));
            make.top.equalTo(lineLab.mas_top).offset(150);
            make.left.equalTo(lab1.mas_right).offset(width);
        }];
        
        
        
        UILabel *lab3 = [[UILabel alloc] init];
        //lab3.textColor = OverColor;
        lab3.font = [UIFont systemFontOfSize:12];
        //lab3.backgroundColor = [UIColor blueColor];
        lab3.text = @"认筹";
        lab3.textAlignment = NSTextAlignmentCenter;
        [self addSubview:lab3];
        [lab3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(width, 15));
            make.top.equalTo(lineLab.mas_top).offset(150);
            make.left.equalTo(lab2.mas_right).offset(width);
        }];
        
        
        
        
        UILabel *lab4 = [[UILabel alloc] init];
       // lab4.textColor = OverColor;
        lab4.font = [UIFont systemFontOfSize:12];
        //lab4.backgroundColor = [UIColor blueColor];
        lab4.text = @"认购";
        lab4.textAlignment = NSTextAlignmentCenter;
        [self addSubview:lab4];
        [lab4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(width, 15));
            make.top.equalTo(lineLab.mas_top).offset(150);
            make.left.equalTo(lab3.mas_right).offset(width);
        }];
        
        UILabel *lab5 = [[UILabel alloc] init];
        //lab5.textColor = OverColor;
        lab5.font = [UIFont systemFontOfSize:12];
        //lab5.backgroundColor = [UIColor blueColor];
        lab5.text = @"签约";
        lab5.textAlignment = NSTextAlignmentCenter;
        [self addSubview:lab5];
        [lab5 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(width, 15));
            make.top.equalTo(lineLab.mas_top).offset(150);
            make.right.equalTo(self.mas_right).offset(-width);
        }];
        
        
        
        
        


        UILabel *title_Lab = [[UILabel alloc] init];
        title_Lab.text = @"我的工作安排";
        title_Lab.textColor = [UIColor blackColor];
        title_Lab.font = [UIFont systemFontOfSize:14];
        [self addSubview:title_Lab];
        
        [title_Lab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_offset(CGSizeMake(100, 20));
            make.left.equalTo(self.mas_left).offset(15);
            make.top.equalTo(_twoView.mas_bottom).offset(10);
        }];
        

    }
    return self;
}

-(void)didTDGuWenWork:(NSNotification *)notifi
{
    if (notifi.object != 0)
    {
        int status = [[notifi.object objectForKey:@"status"] intValue];
        if (status == 1)
        {
            _deleDic = [notifi.object objectForKey:@"data"];
             _paiMLab.text = [_deleDic objectForKey:@"paiming"];
            //_timeLab.text = [_deleDic objectForKey:@"date"];
            _timeLab.text = [NSString stringWithFormat:@"%@ |",[_deleDic objectForKey:@"date"]];
            _finishLab.text = [[_deleDic objectForKey:@"yeji"] objectForKey:@"finish_price"];
            NSString *biStr = [[_deleDic objectForKey:@"yeji"] objectForKey:@"finish_bl"];
            _biLiLab.text = [NSString stringWithFormat:@" 完成比例 : %@ %%",biStr];;
             NSString *zongStr = [[_deleDic objectForKey:@"yeji"] objectForKey:@"all_money"];
            _allLab.text = [NSString stringWithFormat:@"| %@万",zongStr];
            [_proView setProgress:[biStr intValue]*0.01 animated:NO];
            
            _laiDLab.text = [[_deleDic objectForKey:@"month_data"] objectForKey:@"caller_num"];
            _laiFLab.text = [[_deleDic objectForKey:@"month_data"] objectForKey:@"visit_num"];
            _chouLab.text = [[_deleDic objectForKey:@"month_data"] objectForKey:@"renchou_num"];
            _gouLab.text = [[_deleDic objectForKey:@"month_data"] objectForKey:@"rengou_num"];
            _qianLab.text = [[_deleDic objectForKey:@"month_data"] objectForKey:@"sign_num"];
            
     
        }
        else
        {
           // [_manager MakeMyselfAlert:@"获取失败" andIsNeedTitle:NO andShowTime:2.0];
        }
    }
    
    [self.delegate setDelegate:_deleDic];
   
    
    
    
    
}

- (void)setIsrefresh:(BOOL)isrefresh{
    if (isrefresh) {
        _manager = [TodoHttpManager sharedManager];
        NSUserDefaults *userDefa = [NSUserDefaults standardUserDefaults];
        
        NSString *uid= [userDefa objectForKey:@"USER_ID"];
        //工作任务通知
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTDGuWenWork:) name:TDGuWenWork object:nil];
        [_manager userGuWenWorkID:uid];
    }
}



@end
